package com.example.designpatterns.observer;

import com.example.designpatterns.observer.WeatherDisplay;
import com.example.designpatterns.adapter.FahrenheitObserverAdapter;

public class ObserverPatternDemo {
    public static void main(String[] args) {
        WeatherStation weatherStation = new WeatherStation();

        // 创建显示屏1（摄氏度）
        WeatherDisplay display1 = new WeatherDisplay("显示屏1", "℃");
        weatherStation.registerObserver(display1);

        // 创建显示屏2（华氏度），并通过适配器注册
        WeatherDisplay display2 = new WeatherDisplay("显示屏2", "°F");
        weatherStation.registerObserver(new FahrenheitObserverAdapter(display2));

        System.out.println("第一次温度更新...");
        weatherStation.setTemperature(25.5f);

        System.out.println("\n第二次温度更新...");
        weatherStation.setTemperature(28.0f);
    }
}